<template>
  <div class="default-main ba-table-box">
    <div class="block">
      <div class="table-block">
        <el-alert class="ba-table-alert"
                  v-if="baTable.table.remark"
                  :title="baTable.table.remark"
                  type="info"
                  show-icon />
        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
                     :quick-search-placeholder="t('Quick search placeholder', { fields: '订单号' })">
          <template #shop>
            <el-select filterable
                       v-model="baTable.comSearch.form['shop_id']"
                       clearable>
              <el-option v-for="item in shop_arr"
                         :key="item.shop_id"
                         :label="item.shop_name"
                         :value="item.shop_id">
              </el-option>
            </el-select>
          </template>
        </TableHeader>
        <Table show-overflow-tooltip></Table>
      </div>
    </div>
    <EditCom ref="editCom"
             :curRow="curRow" />
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, provide, onBeforeMount } from 'vue'
import baTableClass from '/@/utils/baTable'
// import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { baTableApi } from '/@/api/common'
import Cookies from 'js-cookie'
import { defaultOptButtons } from '/@/components/table'
import { useI18n } from 'vue-i18n'
import { getShopList } from '/@/api/backend/common'
import { concat } from 'lodash-es'
import { useAdminInfo } from '/@/stores/adminInfo'
import EditCom from './editCom.vue'

defineOptions({
    name: 'customer/shopMessages',
})
const { t } = useI18n()
const adminInfo = useAdminInfo()
const editCom: any = ref<InstanceType<typeof EditCom>>()
const curRow = ref({} as anyObj)
const state: {
    buttonLoading: boolean
} = reactive({
    buttonLoading: false
})
let optButtons: OptButton[] = [
    {
        render: 'tipButton',
        name: 'info',
        title: 'Info',
        text:  '手动修改',
        type: 'primary',
        icon: '',
        class: 'newButton',
        disabledTip: true,
        display: (row: TableRow, field: TableColumn) => {
            return baTable.auth('updateShopInfo')
        },
        click: (row: TableRow) => {
            curRow.value = { ...row }
            editCom.value.show = true
        }
    }
]
optButtons = concat(defaultOptButtons(['edit', 'delete']), optButtons)
optButtons[1].display = (row) => {
    return row.id != adminInfo.id
}
const shop_arr = ref([] as any[])
const baTable = new baTableClass(
    new baTableApi('/customer/shopMessages/'),
    {
        column: [
            {
                label: '店铺',
                prop:  'shop_id',
                operator: 'LIKE', 
                comSearchRender:'slot',
                comSearchSlotName: 'shop',
                show: false
            },
            {   
                label: '店铺', 
                prop: 'shop_name', 
                align: 'center',
                operator: false,
                width: 120
            },
            {   
                label: '消息服务', 
                prop: 'status',
                render: 'tag',
                replaceValue: {
                    1: '开启',
                    2: '关闭'
                }, 
                align: 'center',
                operator: false,
                width: 100
            },
            {   
                label: '订单已发消息', 
                prop: 'checkout_letter', 
                align: 'center',
                operator: false
            },
            {
                label: '订单已签收消息', 
                prop: 'reply_letter', 
                align: 'center',
                operator: false
            },
            {
                label: '群发消息', 
                prop: 'batch_letter', 
                align: 'center',
                operator: false
            },
            {
                label: '操作人',
                prop: 'operate_name',
                align: 'center',
                operator: false,
                width: 100
            },
            {
                label: t('Operate'),
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: optButtons,
                operator: false,
            }
        ],
        dblClickNotEditColumn: ['all']
    }
)

provide('baTable', baTable)

baTable.mount()
baTable.getIndex()
const getShopArr = () => {
    getShopList().then(res => {
        if(res.data && res.data.list.length) {
            shop_arr.value = res.data.list
        }
    })
}

onBeforeMount(async () => {
    getShopArr()
})
</script>

<style scoped lang="scss">
:deep(.el-popper.is-dark) {
    max-width: 50%;
}
</style>
